package cate.game.role.farm.dailyfb;

import cate.common.table.d.GDFight;
import cate.common.table.d.GDFunc;
import cate.common.table.d.GDOperation;
import cate.common.table.farm.dailyfb.DailyFbCombatRow;
import cate.game.play.proce.play.PlayPO;
import cate.game.res.MixRes;
import cate.game.role.Role;
import cate.game.role.farm.AbstractFarmFTC;
import cate.game.role.farm.dailyfb.msg.DailyFbChallengeResultResp;
import cate.game.role.farm.dailyfb.msg.DailyFbDataResp;
import easy.java.dev.note.NoteField;

public class DailyFbFTC extends AbstractFarmFTC<MyDailyFb> {
    @NoteField(value = "挑战关卡模板")
    public DailyFbCombatRow tpl;

    public DailyFbFTC(Role role, DailyFbCombatRow tpl) {
        setup(role);
        this.tpl = tpl;
    }

    public DailyFbFTC() {
    }

    @Override
    public void handleResult(Role role, PlayPO play) {
        super.handleResult(role, play);
        boolean win = play.winner == GDFight.Team.A;
        DailyFbChallengeResultResp resultResp = new DailyFbChallengeResultResp();
        resultResp.funcId = GDFunc.DAILY_FB;
        resultResp.win = win;
        if (win) {
            DailyFb fb = role.getFarm().dailyFb.getFb(tpl.type);
            if (fb.playTimes == null)
                fb.initialize(role);
            boolean firstPass = fb.combatNumPass + 1 == this.tpl.combatNum;
            fb.setCombatNumPass(this.tpl.combatNum);
            role.sendNow(new DailyFbDataResp(role));
            if (firstPass) {
                MixRes rewardFirst = new MixRes(this.tpl.rewardFirstCode);
                resultResp.reward = rewardFirst;
                rewardFirst.add(role, true, GDOperation.DAILY_FB_FIRST_PASS_REWARD);
            }
            role.getHistory().action.dailyFBWin(1);
        }

        role.sendNow(resultResp);
        noticeFightOver(role);
    }

    /**
     * 通知前端战斗结束
     */
    private void noticeFightOver(Role role) {
    }

    @Override
    protected MyDailyFb po(Role role) {
        return role.getFarm().dailyFb;
    }

}
